package sort;

/**
 * @author Europa
 * @create 2020-05-15 2:40
 */
public class Shell extends Sort {

    /**
     * 希尔排序<br/>
     * 可视化 https://www.bilibili.com/video/BV1wW411h7Wt
     *
     * @param array int数组
     */
    @Override
    public void sort(int[] array) {
        int length = array.length;
        int h = length / 2;
        // while循环次数取决于 length/2 > 0 的次数
        while (h > 0) {
            // h - length
            for (int i = h; i < length; i++) {
                for (int j = i; j >= h; j -= h) {
                    if (less(array[j], array[j - h])) {
                        exchange(array, j, j - h);
                    }
                }
            }
            h /= 2;
        }

    }
}
